import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
let store = new Vuex.Store({
  // 1. state
  state: {
    city: '城市名',
    test: '',
    showTitleBar: true,
    title: '',
    indexSelectedItem: 0
  },

  // // 2. getters
  getters: {
    // 参数列表state指的是state数据
    getCityFn (state) {
      return state.city
    },
    getTitle (state) {
      return state.title
    },
    getIndexSelectedItem (state) {
      return state.indexSelectedItem
    }
  },
  // 3. actions
  // 通常跟api接口打交道
  actions: {},
  // 4. mutations
  mutations: {
    // state指的是state的数据
    // name传递过来的数据
    setCity (state, name) {
      state.city = name// 将传参设置给state的city
    },
    setShowTitleBar (state, show) {
      state.showTitleBar = show
    },
    setTitle (state, title) {
      state.title = title
    },
    setIndexSelectedItem (state, indexSelectedItem) {
      state.indexSelectedItem = indexSelectedItem
    }
  }
})

export default store
